package com.fm.service;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.net.Socket;
import java.util.Properties;
import java.util.Set;

@Slf4j
public class service_ListFile {

    /**
     * 列表
     *
     * @param socket
     */
    public static void ListFile(Socket socket) {

        //获取列表
        try {
            Properties properties = new Properties();
            properties.load(new FileInputStream("src/main/resources/config.properties"));

            //获取全部值
            StringBuilder values = new StringBuilder();
            Set<String> keys = properties.stringPropertyNames();
            int i = 1;
            for (String key : keys) {
                if (key.startsWith("uploadFileName.")) {
                    // 获取值
                    String value = properties.getProperty(key);
                    values.append(i++).append(". ").append(value).append("\n");
                }
            }

            //传输
            socket.getOutputStream().write(values.toString().getBytes());

            //停止传输 返回-1
            socket.getOutputStream().close();
            socket.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
